<template>
  <div class="InviteBidding">
    <!--banner-->
    <div class="banner">
      <div class="wh-1200 auto banner-txt pt-50">
        <h1>招标公告</h1>
        <span>Bidding Announcement</span>
      </div>
    </div>

    <!--招商合作-->
    <div class="wh-1200 auto main mt-40">
      <!-- 标题模块 -->
      <div class="main-title mt-40">
        <img src="@/assets/images/Bidding.png" alt />
        <span>招标公告</span>
      </div>

      <!-- 搜索模块 -->
      <div class="main-search">
        <a-form-model :label-col="{span:2}">
          <a-form-model-item label="关键字">
            <a-input v-model="form.keyword" placeholder="请输入公告标题" />
            <a-button class="ant-btn1" @click="SearchData">搜索</a-button>
            <!-- <span @click="show=!show" v-show="!show" class="show-btn">
              高级搜索
              <a-icon type="caret-right" />
            </span>
            <span @click="show=!show" v-show="show" class="show-btn" style="color: #188af1;">
              高级搜索
              <a-icon type="caret-down" />
            </span> -->
          </a-form-model-item>
        </a-form-model>

        <!-- <div v-show="show">
          <div>
            <a-form-model class="mt-10" :label-col="{span:2}" :wrapper-col="{span:14}">
              <a-form-model-item label="招标类型" prop="type">
                <a-checkbox-group v-for="(item,index) in BiddingType" :key="index">
                  <a-checkbox value="item.key" name="type">{{item.label}}</a-checkbox>
                </a-checkbox-group>
              </a-form-model-item>
              <a-form-model-item label="行业类别：">
                <a-select placeholder="请选择" style="width: 120px" class="mr-32">
                  <a-select-option v-for="(item, index) in selectType" :key="index" :value="item.name">{{ item.name }}</a-select-option>
                </a-select>
                <a-select placeholder="请选择" style="width: 120px" class="mr-32">
                  <a-select-option v-for="(item, index) in selectType" :key="index" :value="item.name">{{ item.name }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-form-model>
          </div>
        </div> -->
      </div>

      <div class="main-searchResult clearfix" v-if="TableData.length>0">
        <div class="f-left search-left">
          <span v-if="newskeyword != ''">

            搜索："
            <span class="search-text1">{{newskeyword}}</span>
            "
          </span>共
          <span class="search-text2">{{total}} </span>条数据
        </div>
        <div class="f-right search-right clearfix">
          <a-button @click="SwitchisOrderDesc" v-show="nowIndex == 1">

            <div class="f-left search-right-icon">
              <div>
                <a-icon :class="!form.isOrderDesc ?'':'down'" type="caret-up" />
              </div>
              <div>
                <a-icon :class="form.isOrderDesc ?'':'down'" type="caret-down" />
              </div>
            </div>
            <div class="f-left remainingTime">发布时间</div>
          </a-button>
        </div>
      </div>

      <!--列表模块-->
      <div class="list-box">
        <ul class="tabs">
          <li class="li-tab" v-for="(item, index) in tabsParam" :key="index" @click="toggleTabs(index)" :class="{ active: index == nowIndex }">
            {{ item }}
          </li>
        </ul>
        <!--全部-->
        <!-- <div class="divTab" v-show="nowIndex === 0">
          <ul>
            <li class="pb-16 pt-8 pr-8 mt-16" v-for="(item, index) in TableData" :key="index">
              <div class="list-dot"></div>
              <div class="pl-32">
                <h1 class="list-title pb-8" @click="toDetail(item.id)">
                  {{item.title?item.title:'无'}}
                </h1>
                <span class="time">{{item.publishDate}}</span>
              </div>
            </li>
          </ul>
        </div> -->
        <!--政府招标-->
        <div class="divTab" v-if="nowIndex === 0">
          <ul>
            <li class="pb-16 pt-8 pr-8 mt-16" v-for="(item, index) in TableData" :key="index">
              <div class="list-dot"></div>
              <div class="pl-32">
                <h1 class="list-title pb-8" @click="toDetail(item)">
                  {{item.title?item.title:'无'}}
                </h1>
                <span class="time">{{item.pubtime}}</span>
              </div>
            </li>
          </ul>
        </div>

        <!--企业招标-->
        <div class="divTab" v-if="nowIndex === 1">
          <ul>
            <li class="pb-16 pt-8 pr-8 mt-16" v-for="item in TableData" :key="item.id">
              <div class="list-dot"></div>
              <div class="pl-32">
                <h1 class="list-title pb-8" @click="toDetail(item)">
                  {{item.title?item.title:'无'}}
                </h1>
                <span class="time">{{item.createTime}}</span>
              </div>
            </li>
          </ul>
        </div>
        <NoData v-if="TableData.length<=0" :Keywords="newskeyword"></NoData>
        <div v-if="TableData.length>0" class=" mt-40 tc mb-100">
          <a-pagination :show-total="total => `共有 ${total} 条数据`" show-quick-jumper :current="form.current"
            @showSizeChange="showSizeChanger" show-size-changer :defaultPageSize="10" :pageSize='form.size' 
            :pageSizeOptions="['10', '20', '30', '40']" :total="total" @change="onChange" />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import NoData from "@/components/Nodata";
import { getentMerchantsList, getzf } from "@/apis/EntMerchants";
export default {
  data() {
    return {
      newskeyword: "",
      tabsParam: ["政府招标", "企业招标"], //（这个也可以用对象key，value来实现）
      nowIndex: 0, //默认第一个tab为激活状态
      show: false,
      BiddingType: [
        { label: "企业招标", key: 1 },
        { label: "政府招标", key: 2 },
      ],
      selectType: [
        { name: "电子", key: 1 },
        { name: "织纺", key: 2 },
        { name: "化工", key: 3 },
        { name: "建材", key: 4 },
        { name: "机械", key: 5 },
        { name: "轻工", key: 6 },
        { name: "食品", key: 7 },
        { name: "冶金", key: 8 },
        { name: "制药", key: 9 },
        { name: "通用服务", key: 10 },
        { name: "抗议物资", key: 11 },
      ],
      total: 10,
      form: {
        type: 2, //1招商，2招标
        size: 10,
        keyword: "",
        isOrderDesc: true,
        current: 1,
        auditStatus: 2,
      },
      TableData: [],
    };
  },
  created() {
    // this.getentMerchantsList();
    this.getzf();
  },
  components: {
    NoData,
  },
  methods: {
    SearchData() {
      if (this.form.keyword != "") {
        this.newskeyword = this.form.keyword;
      } else {
        this.newskeyword = "";
      }
      this.onChange(1)
    },
    toDetail(item) {
      if (this.nowIndex == 1) {
        this.$router.push("/InviteBiddingDetails?merchantsid=" + item.id);
      } else {
        localStorage.setItem("zfinfo", JSON.stringify(item));
        this.$router.push("/zfInviteBiddingDetails?merchantsid=" + item.id);
      }
    },
    //排序
    SwitchisOrderDesc() {
      this.form.isOrderDesc = !this.form.isOrderDesc;
      this.getentMerchantsList();
    },

    // 当前页
    onChange(page, pageSize) {
      this.form.current = page;
      if (this.nowIndex === 1) {
        this.getentMerchantsList();
      } else {
        this.getzf();
      }
    },
    //每页显示条数
    showSizeChanger(current, size) {
      this.form.size = size;
      this.form.current = current;
      if (this.nowIndex === 1) {
        this.getentMerchantsList();
      } else {
        this.getzf();
      }
    },

    // 获取招商合作列表
    getentMerchantsList() {
      let _param = {
        type: 2,
        size: this.form.size,
        keyword: this.newskeyword,
        isOrderDesc: this.form.isOrderDesc,
        current: this.form.current,
        auditStatus: 2,
      }
      getentMerchantsList(_param)
        .then((res) => {
          console.log("招标列表");
          console.log(res);
          if (res.code == 200) {
            this.TableData = res.data.records;
            this.total = res.data.total;
          }
        })
        .catch((error) => {});
    },
    toHomePage() {
      this.$router.push("/homePage");
    },
    toggleTabs(index) {
      this.nowIndex = index;
      this.form.current = 1;
      this.form.size = 10;
      this.form.keyword = ''
      this.newskeyword = ''
      if(this.TableData.length > 0) {
        this.TableData = []
      }
      if (index == 0) {
        this.getzf();
      } else {
        this.getentMerchantsList();
      }
    },
    clear() {
      this.$refs.ruleForm.resetFields();
    },

    //政府招标
    getzf() {
      let _param = {
        endTime: "",
        keyword: "",
        page: this.form.current,
        size: this.form.size,
        startTime: "",
        titKeyword: this.newskeyword,
      };
      getzf(_param)
        .then((res) => {
          // console.log("aaa");
          // console.log(res);
          if (res.code === "000000") {
            this.total = res.data.total;
            this.TableData = res.data.records;
          }
        })
        .catch((err) => {
          console.error(err);
        });
    },
  },
};
</script>
<style lang="less" scoped>
.InviteBidding {
  .banner {
    background: url("../../../assets/images/attract.png") no-repeat center;
    height: 200px;
    h1 {
      height: 60px;
      line-height: 60px;
      color: rgb(7, 41, 71);
      font-size: @font36;
      font-weight: lighter;
    }
    span {
      font-size: @font36;
      color: rgba(7, 41, 71, 58%);
    }
  }
  .main-title {
    img {
      width: 40px;
      height: 40px;
      margin-right: 16px;
      vertical-align: middle;
      margin-top: -10px;
    }

    span {
      font-family: Microsoft YaHei;
      font-size: @font26;
      line-height: @font26;
      font-weight: 700;
      color: @text-color-303;
    }
  }

  .main-search {
    margin-top: 24px;
    margin-bottom: 24px;
    ::v-deep .ant-col-2 {
      width: auto !important;
    }
    &:nth-child(1) {
      font-family: Microsoft YaHei;
      font-size: @font14;
      font-weight: normal;
      line-height: 19px;
      color: @text-color-606;
      margin-right: 8px;
    }

    .ant-input {
      width: 500px;
      height: 40px;
    }

    .ant-btn1 {
      margin-left: 12px;
      margin-right: 40px;
      width: 100px;
      height: 40px;
      background-color: #2a51bc;
      box-shadow: 0px 10px 20px 0px rgba(7, 41, 71, 0.16);
      border-radius: 4px;
      color: #fff;
    }

    .show-btn {
      cursor: pointer;

      &:hover {
        color: #188af1;
      }
    }

    &:nth-child(4) {
      font-family: Microsoft YaHei;
      font-size: @font16;
      font-weight: normal;
      line-height: 21px;
      color: @text-color-606;
    }
  }

  .main-searchResult {
    height: 70px;
    line-height: 70px;
    background-color: #fff;
    box-shadow: 0px 3px 10px 0px rgba(24, 138, 241, 0.16);
    border-radius: 4px;
    margin-bottom: 32px;

    .search-left {
      margin-left: 26px;
      font-size: @font16;

      .search-text1 {
        color: #2a51bc;
      }

      .search-text2 {
        color: #e9284f;
        font-weight: 700;
      }
    }

    .search-right {
      margin-right: 24px;

      .ant-btn {
        margin-left: 16px;
        width: 120px;
        height: 40px;
        line-height: 1;
        border: solid 1px #188af1;
        color: #188af1;
        font-size: @font16;

        &:hover {
          background-color: #188af1;
          color: #fff;
        }
      }

      .down {
        opacity: 0.5;
      }
      .remainingTime {
        padding-left: 5px;
        line-height: 32px;
      }
      .search-right-icon {
        div {
          width: 14px;
          height: 9px;
        }
        padding-top: 3px;
      }
    }
  }

  .list-box {
    .tabs {
      border-bottom: 1px solid #ebeef5;
      height: 40px;
      font-size: @font16;
      .li-tab {
        float: left;
        line-height: 40px;
        width: 88px;
        text-align: center;
        margin-right: 24px;
        color: @text-color-909;
        position: relative;
        cursor: pointer;
      }
      .active {
        color: @text-color-303;
        font-weight: bold;
      }
      .active:before {
        width: 20px;
        height: 4px;
        content: "";
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translate(-50%, 0);
        background-color: #2a51bc;
      }
    }
    .divTab {
      ul li {
        position: relative;
        border-bottom: 1px solid #e4e7ed;
        &:hover {
          cursor: pointer;
        }
        .list-dot {
          width: 8px;
          height: 16px;
          background: #188af1;
          position: absolute;
          top: 12px;
          left: 8px;
        }
        div {
          .list-title {
            font-size: @font18;
            &:hover {
              color: @color-188;
            }
          }
          .time {
            position: absolute;
            right: 8px;
            top: 16px;
            color: @text-color-909;
          }
        }
      }
    }
  }
}
</style>